package org.tio.sitexxx.service.service.qj;

import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.SqlPara;
import org.tio.sitexxx.service.model.main.Follower;
import org.tio.sitexxx.service.vo.Const;

import java.util.List;
import java.util.Map;

public class FollowerService {
    public static final FollowerService me  = new FollowerService();
    final Follower dao = new Follower().dao();

    public void create(Follower follower){
        follower.save();
    }

    public Follower getFollower(Map<String, Object> kv){
        SqlPara sqlPara = Db.use(Const.Db.TIO_SITE_MAIN).getSqlPara("follower.getFollower",kv);
        return dao.findFirst(sqlPara) ;
    }

    public int delete(Map<String, Object> query){
        String sqlid = "follower.deleteFollower";
        String db = Const.Db.TIO_SITE_MAIN;
        Kv cond=Kv.create().set(query);
        Integer count=0;
        try{
            SqlPara sqlPara = Db.use(db).getSqlPara(sqlid,cond);
            count=Db.use(db).delete(sqlPara.getSql(),sqlPara.getPara());
        }catch (Exception e){
            e.printStackTrace();
        }
        return count;
    }


    public List<Follower> getFollowers(Map<String, Object> kv){
        SqlPara sqlPara = Db.use(Const.Db.TIO_SITE_MAIN).getSqlPara("follower.getFollowers",kv);
        return dao.find(sqlPara);
    }
}
